
<?php include './application/views/top.php'; ?>
<script src="/static/js/gsdai.js"></script>
<script src="/static/js/ajaxfileupload.js"></script>
<script src="/static/js/My97DatePicker/WdatePicker.js"></script>
<script src="/static/js/formCheck.js"></script>

<div class="clear"></div>
<div class="user_bottom all"></div>
<div class="clear h50"></div>
<div class="layout uc">
	<?php include './application/views/user/left.php'; ?>
	<div class="right">
		<div class="menu_list"><?php include './application/views/user/menu.php'; ?></div>
        <div class="cont">
			<form id="del_form">
			<input type="hidden" name="id" value="<?php echo isset($info['id']) ? $info['id']: 0;?>">
			<input type="hidden" name="is_receive" value="<?php echo isset($info['is_receive']) ? $info['is_receive']: 0;?>">
			</form>
            <div class="fr">
            <input type="button" value="返回列表" onclick="back('<?php echo isset($info['is_receive']) ? $info['is_receive']: 0;?>');" class="p_button" />
			<input type="button" value="删除" onclick="del();" class="p_button" />
			</div>
            <?php if($msg=='' && isset($info['id'])){?>
            <form id="message_view_form">
            <dl class="line">
            	<dt>标题：</dt>
                <dd>
				<input type="hidden" name="name" value="回复：<?php echo $info['name'];?>">
				<?php echo $info['name']; ?>
                </dd>
			</dl>
            <?php if($info['is_receive'] == 1){?>
            <dl class="line">
            	<dt>发送人：</dt>
                <dd>
				<input type="hidden" name="receive_user" value="<?php echo $info['sent_user'];?>">
				<?php echo $info['sent_username']; ?>
                </dd>
			</dl>
            <?php }else{?>
            <dl class="line">
            	<dt>收信人：</dt>
                <dd><?php echo $info['receive_username']; ?></dd>
			</dl>
            <?php }?>
            <dl class="line">
            	<dt>发送内容：</dt>
                <dd><?php echo $info['content']; ?></dd>
			</dl>
            <?php if($info['is_receive'] == 1){?>
            <dl class="line">
            	<dt>回复：</dt>
                <dd><textarea id="reply_content" name="content" style="width: 330px;height: 150px;"></textarea></dd>
			</dl>
            <div class="cb"><input class="button" type="submit" value="确认提交" onclick="reply();" /></div>            
            <?php }?>
            </form>
        	<?php }?>
		</div>
	</div>
</div>
<div class="clear h50"></div>
<?php include "./application/views/footer.php";?>
<script>
<?php if($msg!=''){?>
$(function(){
	$('#dialog').dialog({
		modal:true,
		title:'系统提示',
		buttons:{"确定":function(){$(this).dialog("close");}},
		close: function() {
			location='/message/received';
		}
	}); 
	$("#msg").html("<?php echo $msg;?>");
});

<?php }?>

function back(a){
	if(a==1){
		window.location='/message/received';
	}else{
		window.location='/message/sendbox';
	}
}

function del(){
	var options = {
		url : '/message/dodel',
		//clearForm :true,
		//resetForm :true,
		//beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						location='/message/received';
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#del_form").ajaxSubmit(options);
	return false;
}

function reply(){
	var options = {
		url : '/message/dosent',
		//clearForm :true,
		//resetForm :true,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						//location=ret.data.url;
						if(ret.data.url==''){
							window.location.reload();
						}else{
							window.location=ret.data.url;
						}
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#message_view_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var a = "<?php echo $info['sent_user'];?>";
	if(a<2){
		$('#dialog').dialog({
			modal:true,
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}},
			close: function() {
				$("#message_view_form").resetForm();
			}
		}); 
		$("#msg").html("系统信件请不要回复");
		return false;
	}
	if($("#reply_content").val()==''){
		$('#dialog').dialog({
			modal:true,
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}},
			close: function() {
				$("#message_view_form").resetForm();
			}
		}); 
		$("#msg").html("回复内容为空");
		return false;
	}
	
	return true;
}
</script>